Question: 1 -
4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators?a = 4
b = 11
print(a | b)
print(a >> 2)
-
15
10 -
1
15 -
14
1 -
15
1
Answer:
15
1
Solution:
Bitwise right shift operator(>>): The a’s value is moved right by the 2 bits.
Bitwise right shift operator(>>): The a’s value is moved right by the 2 bits.
Question: 2 -
Which of the following operators has the highest precedence?
-
+
-
&
-
*
-
not
Answer:
*
Solution not available.
Question: 3 -
What is the output of the following codeprint(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
-
False True True True
-
- True True False True
-
True True False True
-
False True False True
Answer:
- If we pass A zero value to
bool()constructor, it will treat it as a booleanFalse. - Any non-zero value will be treated as a boolean
True.
False True True True
Solution:
Question: 4 -
What is the output of the expression print(-18 // 4)
-
4
-
-4
-
-5
-
5
Answer:
-5
Solution:
In the case of floor division operator (//), when the result is negative, the result is rounded down to the next smallest (big negative) integer.
In the case of floor division operator (//), when the result is negative, the result is rounded down to the next smallest (big negative) integer.
Question: 5 -
What is the output of the following codex = 100
y = 50
print(x and y)
-
False
-
50
-
True
-
100
Answer:
50
Solution:
In Python, When we join two non-Boolean values using a and operator, the value of the expression is the second operands, not True or False.
In Python, When we join two non-Boolean values using a and operator, the value of the expression is the second operands, not True or False.